package com.zhm.demo;

public class CronExpressionGenerator {

    /**
     * Generate a Quartz cron expression string based on a given seconds interval.
     * The cron expression will repeat the task every N seconds within each minute.
     *
     * @param secondsInterval The interval in seconds.
     * @return The cron expression string.
     */
    public static String generateCronExpression(int secondsInterval) {
        // Check if the interval is valid (positive and less than 60)
        if (secondsInterval <= 0 || secondsInterval >= 60) {
            throw new IllegalArgumentException("Seconds interval must be between 1 and 59.");
        }

        // Generate the cron expression
        // "0/N * * * * ?" where N is the seconds interval
        return String.format("0/%d * * * * ?", secondsInterval);
    }

    public static void main(String[] args) {
        // Example usage
        int secondsInterval = 10; // Example: Every 10 seconds
        String cronExpression = generateCronExpression(secondsInterval);
        System.out.println("Cron Expression: " + cronExpression); // Output: Cron Expression: 0/10 * * * * ?
    }
}